<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/17
 * Time: 18:52
 */
session_start();
$key=$_COOKIE['taken'];
if(empty($_SESSION[$key])){
    echo '未登录，请登录<br/><a href="../admin/admin_login.php">登陆</a>';
    die();
}
//获取前台数据
$user_name=$_POST['user_name'];
$Account_Code=$_POST['Account_Code'];
$Account_phone=$_POST['Account_phone'];
if(empty($user_name)||empty($Account_Code)||empty($Account_phone)){
    echo '不能为空,<a href="open_account.php"><button>返回</button></a>';
    die();
}
//与数据库建立连接
$conn=new  mysqli('127.0.0.1','root','root','bank');
//判断该用户是否已存在
$sql="select * from accountinfo where  RealName='$user_name' and  AccountCode='$Account_Code'";
$result=$conn->query($sql);
if($conn->affected_rows>0){
    echo '已存在该账户<br/><a href="../admin/adminlogin_action.php">返回</a>';
    die();
}else{
    $sql="INSERT INTO accountinfo(AccountCode,AccountPhone,RealName,OpenTime) VALUES
('$Account_Code','$Account_phone','$user_name',NOW());
  ";
    $conn->query($sql);
    if($conn->affected_rows>0){
        echo '开户成功<br/><a href="../admin/adminlogin_action.php">返回</a>';
    }
}